<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :maskClosable="false"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
  >
    <j-vxe-table
      keep-source
      ref="xTable"
      :loading="bisAccountValueTable.loading"
      :columns="bisAccountValueTable.columns"
      :dataSource="bisAccountValueTable.dataSource"
      :maxHeight="300"
      :disabled="formDisabled"
      :rowNumber="false"
      :rowSelection="false"
      :toolbar="false"
    >
    </j-vxe-table>
  </a-modal>
</template>

<script>
import { getAction, getFileAccessHttpUrl, httpAction, postAction } from '@/api/manage'
import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
import { JVXETypes } from '@/components/jeecg/JVxeTable'
import { getRefPromise, VALIDATE_FAILED } from '@/components/jeecg/JVxeTable/utils/vxeUtils.js'
import { validateDuplicateValue } from '@/utils/util'
import JFormContainer from '@/components/jeecg/JFormContainer'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
export default {
  name: 'AccountValueModal',
  mixins: [JVxeTableModelMixin],
  components: {
    JFormContainer,
  },
  data() {
    return {
      title: this.$t('运营设置'),
      width: 900,
      visible: false,
      disableSubmit: false,
      addDefaultRowNum: 1,
      // 商品BOM清单
      bisAccountValueTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: this.$t('账户类型'),
            key: 'type',
            type: JVXETypes.select,
            width: '400px',
            disabled: true,
            dictCode: 'bis_account_value.type',
            validateRules: [{ required: true, message: this.$t('${title}不能为空') }],
            align: 'center'
          },
          {
            title: this.$t('账户价值'),
            key: 'value',
            type: JVXETypes.inputNumber,
            width: '350px',
            placeholder: this.$t('请输入${title}'),
            defaultValue: '',
            validateRules: [{ required: true, message: this.$t('${title}不能为空') }],
            align: 'center'
          },
        ],
      },
      validRules: {
        type: [{ required: true, message: this.$t('请选择账户类型') }],
        value: [{ required: true, message: this.$t('请输入账户价值') }],
      },
      url: {
        list: '/game/bisAccountValue/list',
        edit: '/game/bisAccountValue/edit',
      },
      model: {},
      productTypes: [],
      queryParam: {}
    }
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
  },
  methods: {
    show() {
      let that = this
      that.visible = true
      that.bisAccountValueTable.dataSource = []
      that.model = {}
      that.getList()
    },
    getList: function () {
      let that = this,
        query = {}
      query.pageSize = 999
      getAction(that.url.list, query).then((res) => {
        if (res.success) {
          that.bisAccountValueTable.dataSource = res.result.records
        } else {
          that.$message.error(res.message)
        }
      })
    },
    handleOk() {
      let that = this,
      url = that.url.edit,
      methods = 'put',
      tableDate = []
      tableDate = this.$refs.xTable.getTableData()
      that.$refs.xTable.validateTable().then((errMap) => {
        if (!errMap) {
          let query = {
            valueList: tableDate,
          }
          httpAction(url, query, methods).then((res) => {
            if (res.success) {
              that.$message.success('操作成功！')
              that.$emit('ok')
              that.close()
            } else {
              that.$message.error(res.message)
            }
          })
        }
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    getImgView(text) {
      if (text && text.indexOf(',') > 0) {
        text = text.substring(0, text.indexOf(','))
      }
      return getFileAccessHttpUrl(text)
    },
    //校验所有一对一子表表单
    validateSubForm(allValues) {
      return new Promise((resolve, reject) => {
        Promise.all([])
          .then(() => {
            resolve(allValues)
          })
          .catch((e) => {
            if (e.error === VALIDATE_FAILED) {
              // 如果有未通过表单验证的子表，就自动跳转到它所在的tab
              this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
            } else {
              console.error(e)
            }
          })
      })
    },
  },
}
</script>

<style scoped>
</style>